<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
    
	public function index(){
		$this->display('Login/login');
	}
	
	public function login(){
		
		if(!IS_POST){
			$this->display('Login/login');
		}else{
			$data = I('post.');
			$model = D('User');
			$userData = $model->where(array('username' => $data['username']))->find();
			if($userData == NULL){
				$this->error('用户名不存在');
			}
			if($userData['userpwd'] != md5($data['userpwd'])){
				$this->error('密码错误');
			}
			
			$_SESSION['username'] = $userData['username'];
			$_SESSION['id'] = $userData['id'];
			$_SESSION['type'] = $userData['type'];
			$this->success('登陆成功', U("Home/Index/index"), 1);
		}
		
	}
		
}